package task

import (
	common "Monitor/common"
)

//基本任务结构
type TaskBase struct {
	//Entry        *gtimer.Entry
	Request      *TaskRequest
	Response     *TaskResponse
	Name         string
	TaskCallback func(req *TaskRequest, resp *TaskResponse)
}

//任务请求
type TaskRequest struct {
	RequestCallParams *TaskRequestParams
	RequestCallback   func(p *TaskRequest, q *TaskResponse)
	Reply             common.TaskIf
	Logger            *common.CommonLogger
	Cache             *common.CommonCache
}

//任务请求参数结构
type TaskRequestParams struct {
	CommString string
}

//任务结果
type TaskResponse struct {
	ResponseCallParams *TaskResponseParams
	ResponseCallback   func(p *TaskRequest, q *TaskResponse)
}

//任务结果参数
type TaskResponseParams struct {
	CommString string
}

func NewTask() (t *TaskBase) {
	t = &TaskBase{
		Response: NewTaskResponse(),
		Request:  NewTaskRequest(),
	}
	return
}

func NewTaskRequest() (req *TaskRequest) {
	req = &TaskRequest{
		Logger: common.BLogger,
		Cache:  common.BCache,
	}
	return
}

func NewTaskResponse() (resp *TaskResponse) {
	resp = &TaskResponse{}
	return
}

func NewTaskRequestParams(s string) (req *TaskRequestParams) {
	req = &TaskRequestParams{
		CommString: s,
	}
	return
}

func NewTaskResponseParams() (resp *TaskResponseParams) {
	resp = &TaskResponseParams{}
	return
}

func (t *TaskBase) SetName(name string) {
	t.Name = name
}

func (t *TaskBase) DefaultTask() {
	t.TaskCallback(t.Request, t.Response)
}
